package com.yj.question_project.domain;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @Auther: starsky1
 * @Date: 2024/01/10 17:42
 * @Description: todo
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class VNode implements Serializable {
    /**
     *
     */
    private Long id;
    private Integer staId;
    private String staName;
    private List<VNode> relateNodes = new ArrayList<>();
    private Set<MetroLine> belongLines = new HashSet<>();
    /**
     * 是否为中转站
     * 1 是 中转站
     * 0 普通节点
     *
     */
    private Integer staType;

    /**
     * 站点在地图上的横坐标
     */
    private Integer x;

    /**
     * 站点在地图上的纵坐标
     */
    private Integer y;

    /**
     * 站点图标颜色
     */
    private String staColor;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 删除标记 0 未删除 1 已删除
     */
    private Integer isDel;

    /**
     * qp_metro_station
     */
    private static final long serialVersionUID = 1L;

    public VNode(Integer staId, String staName) {
        this.staId = staId;
        this.staName = staName;
        this.x = 0;
        this.y = 0;
    }

    public VNode addRelateVNode(VNode node) {
        if (!this.relateNodes.contains(node)) {
            this.relateNodes.add(node);
        }
        return this;
    }

    public VNode addLine(MetroLine line) {
        this.belongLines.add(line);
        return this;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        if (obj instanceof VNode) {
            VNode v1 = (VNode) obj;
            if (this.staId == null && v1.staId == null) {
                return true;
            }
            if (this.staId.equals(v1.staId)) {
                return true;
            }
        }
        return false;
    }

    @Override
    public int hashCode() {
        return this.staId.hashCode();
    }

    public String staNameToString() {
        return this.getStaName() + Arrays.toString(this.belongLines.stream().toArray());
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("VNode ").append(staId).append(":").append(staName).append("\n");
        sb.append("relateNodes: ");
        if (relateNodes.size() > 0) {
            for (VNode node : relateNodes) {
                sb.append(node.getStaName()).append(Arrays.toString(node.belongLines.stream().toArray())).append(",");
            }
            sb.deleteCharAt(sb.length() - 1).append("\n");
        }
        sb.append("belongLines: ");
        for (MetroLine line : belongLines) {
            sb.append(line).append(",");
        }
        sb.deleteCharAt(sb.length() - 1).append("\n");
        return sb.toString();
    }
}
